package test;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author oldliu
 * @since 1.0
 */
public class HAnzi3 {
    public static void main(String[] args) {

        String[] shu = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
        String[] danwei = {"", "十", "百", "千"};//, "万", "十", "百", "千", "亿"
        String jinwei[]={"","万","亿"};

        int a =106701400;
        String str = String.valueOf(a);
        StringBuilder sb = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        int jw=0;
        for (int i = str.length(); i >= 0; i -= 4) {
            String d = str.substring(i<=4?0:i - 4, i);
            System.out.println(d);
            char[] cr = d.toCharArray();
            for (int j = 0; j < cr.length; j++) {
                int k=cr[j]-'0';
                if(k>0){
                    sb.append(shu[k]);
                    sb.append(danwei[cr.length-1-j]);
                }else{
                    //查看sb的最后一个是不是0
                    if(sb.length()==0)
                    {
                        sb.append('零');
                        continue;
                    }
                    if(sb.charAt(sb.length()-1)=='零'){
                        continue;
                    }
                    sb.append('零');
                }

            }
            //最后连续的0，去掉.
            System.out.println("zhi前:"+sb);
            for (int l = sb.length()-1; l>=0; l--) {
                if(sb.charAt(l)!='零')
                {
                    break;
                }
                sb.deleteCharAt(l);
            }
            sb.append(jinwei[jw]);
            jw++;
            System.out.println("sb:"+sb);
            sb2.insert(0,sb);
            sb.delete(0,sb.length());
        }
        System.out.println(sb2);
    }
}
